import { request } from '@inbiz/utils';

/**
 * 获取多语言语种列表
 *  * @param params
 */
export async function getKindList(appId: string) {
  return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/kind`, {
    params: {
      appId: appId,
    },
  });
}

/**
 * 查询多语言列表
 *  * @param params
 */
export async function getLanguageList(params: { likeContext?: string; siteType?: 1 | 2 | 4 | 7 }, isWf: boolean, formid: string) {
  return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/${isWf ? 'wfLanguage' : 'language'}`, {
    params: isWf ? {
      likeContext: params.likeContext,
      formOutId: formid
    } : {
      likeContext: params.likeContext,
      siteType: params.siteType
    },
  });
}

/**
 * 新增多语言
 * @param params
 */
export async function setAddLanguage(params: {
  key: string;
  siteType: 1 | 2 | 4 | 7;
  kindItems: {
    kindName: string;
    kindCode: string;
    langText: string;
  }[];
}, isWf: boolean, formid: string) {
  return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/${isWf ? 'wfLanguage' : 'language'}`, {
    method: 'POST',
    data: isWf ? {
      key: params.key,
      kindItems: params.kindItems,
      formOutId: formid
    } : {
      key: params.key,
      kindItems: params.kindItems,
      siteType: params.siteType
    },
  });
}

/**
 * 修改多语言
 * @param params
 */
export async function setEditLanguage(params: {
  key: string;
  siteType: 1 | 2 | 4 | 7;
  kindItems: {
    kindName: string;
    kindCode: string;
    langText: string;
  }[];
}, isWf: boolean, formid: string) {
  return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/${isWf ? 'wfLanguage' : 'language'}`, {
    method: 'PUT',
    data: isWf ? {
      key: params.key,
      formOutId: formid,
      kindItems: params.kindItems
    } : {
      key: params.key,
      siteType: params.siteType,
      kindItems: params.kindItems
    },
  });
}
